<?php
//require_once  __DIR__ . '/includes/authenticate.php';

if (isset($_POST['user_key'])) {

	include_once './db_bb_connect.php';

	$user_key = $_POST['user_key'];
	$firstname = $_POST['firstname'];
	$lastname = $_POST['lastname'];
	$username = $_POST['username'];
	$playernumber = $_POST['playernumber'];
	$position = $_POST['position'];
	$email = $_POST['email'];
	$phonenr = $_POST['phonenr'];
	$birthdate = $_POST['birthdate'];
	$height = $_POST['height'];
	$allowed = $_POST['allowed'];

	$season = $_POST['season'];


	$sql = "UPDATE users 
	SET firstname = '$firstname', lastname = '$lastname', username = '$username', position = '$position', email = '$email', phonenr = '$phonenr', birthdate = '$birthdate', height = '$height', allowed = $allowed
	WHERE user_key = '$user_key'";

	$sql_playernumber = "UPDATE teams 
	SET playernumber = $playernumber
	WHERE playerID = '$user_key'
	AND season = '$season'";

	if( $db->query($sql) ){

		echo "<br/><center>General player info of $firstname $lastname succesfully updated</center>";

		if ( $db->query($sql_playernumber) ){

			echo "<br/><center>Playernumber for season $season succesfully updated</center>";
		} else {
			echo "Error: " . $sql_playernumber . "<br>" . $db->error;
		}

	} else {
		echo "Error: " . $sql . "<br>" . $db->error;
		
	}

}

?>